# ifndef __Globals_H_
# define __Globals_H_

const float c_PI = 3.14159265358979f;
const float c_Sqrt4 = 1.189207115f;

const float c_feet_per_m   = 3.28084f;
const float c_km_per_nmile = 1.852f;
const float c_m_per_nmile  = 1852;
const float c_km_per_smile = 1.6093f;
const float c_m_per_smile  = 1609.3f;

///////////////////////////////////////

class COutOfMemory {
	const size_t m_cRequested;
	const size_t m_cAvailable;
	const bool m_bWarnSmallPageFile;

  public:
	COutOfMemory (size_t _cRequested, size_t _cAvailable, bool _bWarnSmallPageFile) :
		m_cRequested (_cRequested),
		m_cAvailable (_cAvailable),
		m_bWarnSmallPageFile (_bWarnSmallPageFile)
	{}

	size_t RequestedSize () const {return m_cRequested;}
	size_t AvailableSize () const {return m_cAvailable;}
	bool WarnSmallPageFile () const {return m_bWarnSmallPageFile;}

	void Report () const;
};

///////////////////////////////////////

extern bool g_bRegistered;

# ifdef _DEBUG
	# define MAIN_TITLE "GPSMapEdit (DEBUG)"
# else
	# define MAIN_TITLE "GPSMapEdit"
# endif // _DEBUG

void UpdateTitle ();

extern char g_strFileName [MAX_PATH + 1];
class CFileTypeInfo;
extern const CFileTypeInfo * g_pSaverInfo;
extern bool g_bHaveWaypointsOrTracks;

extern char g_strDegreeSign [];
extern size_t g_cDegreeSignLen;

const char * GetStr (size_t _cId);
void LoadString (UINT _uiString, char * _strBuf, size_t _cBufSize);

HMENU LoadMenu (WORD _wID);
HIMAGELIST LoadImageList (WORD _wID, int _nSize, COLORREF _colMask);

INT_PTR DlgBox (WORD _wID, HWND _hWndParent, DLGPROC _pDlgProc, LPARAM _dwInitParam);
INT_PTR DlgBox (WORD _wID, HWND _hWndParent, DLGPROC _pDlgProc);
HWND CreateDlg (WORD _wID, HWND _hWndParent, DLGPROC _pDlgProc, LPARAM _dwInitParam);
HWND CreateDlg (WORD _wID, HWND _hWndParent, DLGPROC _pDlgProc);

void __cdecl ErrorMsgBox   (const char * _strFormat, ...);
void __cdecl WarningMsgBox (const char * _strFormat, ...);
void __cdecl InfoMsgBox    (const char * _strFormat, ...);
bool __cdecl YesNoMsgBox   (const char * _strFormat, ...);

extern bool g_bDialogMode;

extern bool g_bNT;

extern HINSTANCE g_hInst;
extern HINSTANCE g_hResInst;
extern HWND g_hWnd;
extern DWORD g_dwGuiThreadId;

extern HCURSOR g_hArrowCursor;
extern HCURSOR g_hWaitCursor;

//
// Options.
//

extern bool g_bEnableSnapToGrid;
extern bool g_bEnableSticking;
extern bool g_bZoomToFullAfterAdd;
extern bool g_bMSelByShift;

/////////////////////////////////////////////

typedef BOOL (WINAPI * pfAlphaBlend_t) (HDC hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, HDC hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, BLENDFUNCTION blendFunction);
extern pfAlphaBlend_t g_fpAlphaBlend;

/////////////////////////////////////////////

class CWaiter {
  public:
	CWaiter ();
	~CWaiter () {Stop ();}

	void Stop ();
};

/////////////////////////////////////////////

extern HFONT g_hFont;
extern HFONT g_hFixedFont;

const COLORREF c_colBlack     = RGB (0,   0,   0);
const COLORREF c_colWhite     = RGB (255, 255, 255);
const COLORREF c_colLtGray    = RGB (192, 192, 192);
const COLORREF c_colGray      = RGB (128, 128, 128);
const COLORREF c_colDkGray    = RGB (96,  96,  96);
const COLORREF c_colRed       = RGB (255, 0,   0);
const COLORREF c_colDkRed     = RGB (128, 0,   0);
const COLORREF c_colGreen     = RGB (0,   255, 0);
const COLORREF c_colDkGreen   = RGB (0,   128, 0);
const COLORREF c_colBlue      = RGB (0,   0,   255);
const COLORREF c_colDkBlue    = RGB (0,   0,   128);
const COLORREF c_colYellow    = RGB (255, 255, 0);
const COLORREF c_colDkYellow  = RGB (128, 128, 0);
const COLORREF c_colCyan      = RGB (0,   255, 255);
const COLORREF c_colDkCyan    = RGB (0,   128, 128);
const COLORREF c_colMagenta   = RGB (255, 0,   255);
const COLORREF c_colDkMagenta = RGB (128, 0,   128);

extern HPEN g_hpenNull;
extern HPEN g_hpenBlackThin;
extern HPEN g_hpenBlackThick;
extern HPEN g_hpenGrayThin;
extern HPEN g_hpenGrayThick;
extern HPEN g_hpenWhiteThick;
extern HPEN g_hpenRedThin;
extern HPEN g_hpenRedDot;
extern HPEN g_hpenRedThick;
extern HPEN g_hpenGreenThick;

extern HBRUSH g_hbrNull;
extern HBRUSH g_hbrBlack;
extern HBRUSH g_hbrDkRed;
extern HBRUSH g_hbrDkGreen;
extern HBRUSH g_hbrDkYellow;
extern HBRUSH g_hbrDkBlue;
extern HBRUSH g_hbrDkMagenta;
extern HBRUSH g_hbrDkCyan;
extern HBRUSH g_hbrGray;
extern HBRUSH g_hbrLtGray;
extern HBRUSH g_hbrRed;
extern HBRUSH g_hbrGreen;
extern HBRUSH g_hbrYellow;
extern HBRUSH g_hbrBlue;
extern HBRUSH g_hbrMagenta;
extern HBRUSH g_hbrCyan;
extern HBRUSH g_hbrWhite;
extern HBRUSH g_hbrWhiteHatched;

extern HBRUSH g_hbrDkRed_special;
extern HBRUSH g_hbrDkGreen_special;
extern HBRUSH g_hbrDkYellow_special;
extern HBRUSH g_hbrDkBlue_special;
extern HBRUSH g_hbrDkMagenta_special;
extern HBRUSH g_hbrDkCyan_special;
extern HBRUSH g_hbrRed_special;
extern HBRUSH g_hbrGreen_special;
extern HBRUSH g_hbrYellow_special;
extern HBRUSH g_hbrBlue_special;
extern HBRUSH g_hbrMagenta_special;
extern HBRUSH g_hbrCyan_special;

extern HBRUSH g_hbrEmptyMap;
extern HBRUSH g_hbrTmp;
extern HPEN g_hpenGrid;

/////////////////////////////

# define ID_FILE_RECENT_0     2000
# define ID_EDIT_UNDO_0       2100
# define ID_EDIT_REDO_0       2200
# define ID_VIEW_LEVEL_0      2300
# define ID_TOOLS_CREATE_0    2400
# define ID_FILE_IMPORT_0     2500
# define ID_FILE_EXPORT_0     2600
# define ID_TOOLS_TRANSFORM_0 2700
# define ID_VIEW_SCALE_0      2800
# define ID_FAVORITES_0       2900

/////////////////////////////

# define WM_USER_FILE_LOADED (WM_USER + 0) // Sent to g_hWnd.
# define WM_USER_INVOKE      (WM_USER + 1) // Sent to g_hMapWnd.

/////////////////////////////

# define ARRAY_SIZE(x) (sizeof (x) / sizeof (x [0]))

# define INVERT_BYTES(_array) \
	{ \
		for (size_t c = 0; c < sizeof (_array); ++ c) \
			reinterpret_cast<BYTE *> (& _array) [c] = 0xFF - reinterpret_cast<BYTE *> (& _array) [c]; \
	}

COLORREF GetContrastColor (COLORREF _col);

# endif // __Globals_H_